using HKB.Common;
using HKB.Data.Dal;
using HKB.Data.Dal.S_PayInfoTableAdapters;
using System;
using System.Data;
using System.Web;
namespace HKB.Web
{
	public class Shop_PayInfo
	{
		private Conn conn = null;
		private static readonly HLShop_PayInfoTableAdapter Adapter = new HLShop_PayInfoTableAdapter();
		public Shop_PayInfo()
		{
			this.conn = Text.GetComponent<Conn>("conn", HttpContext.Current.CurrentHandler);
		}
		public Shop_PayInfo(Conn _conn)
		{
			this.conn = _conn;
		}
		public bool AddPayInfo(int SalerID, int UserID, string UserName, string eBankID, decimal MoneyPay, decimal MoneyTrue, string OrderFormNum, string Status, string Remark)
		{
			S_PayInfo.HLShop_PayInfoDataTable hLShop_PayInfoDataTable = new S_PayInfo.HLShop_PayInfoDataTable();
			S_PayInfo.HLShop_PayInfoRow hLShop_PayInfoRow = hLShop_PayInfoDataTable.NewHLShop_PayInfoRow();
			hLShop_PayInfoRow.SalerID = SalerID;
			hLShop_PayInfoRow.UserName = UserName;
			hLShop_PayInfoRow.UserID = UserID;
			hLShop_PayInfoRow.PaymentNum = OrderFormNum;
			hLShop_PayInfoRow.eBankID = eBankID;
			hLShop_PayInfoRow.MoneyPay = MoneyPay;
			hLShop_PayInfoRow.MoneyTrue = MoneyTrue;
			hLShop_PayInfoRow.OrderFormNum = OrderFormNum;
			hLShop_PayInfoRow.Remark = Remark;
			hLShop_PayInfoRow.Status = Status;
			hLShop_PayInfoRow.PayTime = DateTime.Now;
			hLShop_PayInfoRow.eBankInfo = "";
			hLShop_PayInfoDataTable.AddHLShop_PayInfoRow(hLShop_PayInfoRow);
			return Shop_PayInfo.Adapter.Update(hLShop_PayInfoDataTable) == 1;
		}
		public bool DeletePayInfo(string PaymentID)
		{
			bool result;
			if (PaymentID == string.Empty)
			{
				result = false;
			}
			else
			{
				int num = this.conn.Execute("Delete From [HLShop_PayInfo] Where PaymentID in(" + PaymentID + ")");
				result = (num >= 1);
			}
			return result;
		}
		public bool updatestatus(string OrderFormNum, string Status, string eBankInfo, decimal MoneyTrue, string PaymentNum)
		{
			S_PayInfo.HLShop_PayInfoDataTable payInfobyOrderFormNum = Shop_PayInfo.Adapter.GetPayInfobyOrderFormNum(OrderFormNum);
			bool result;
			if (payInfobyOrderFormNum.Rows.Count == 0)
			{
				result = false;
			}
			else
			{
				S_PayInfo.HLShop_PayInfoRow hLShop_PayInfoRow = payInfobyOrderFormNum[0];
				hLShop_PayInfoRow.PaymentNum = PaymentNum;
				hLShop_PayInfoRow.Status = Status;
				hLShop_PayInfoRow.eBankInfo = eBankInfo;
				hLShop_PayInfoRow.MoneyTrue = MoneyTrue;
				int num = Shop_PayInfo.Adapter.Update(hLShop_PayInfoRow);
				result = (num == 1);
			}
			return result;
		}
		public bool updateststus(string status, string eBankInfo, int PaymentID)
		{
			S_PayInfo.HLShop_PayInfoDataTable singlePayInfoByID = Shop_PayInfo.Adapter.GetSinglePayInfoByID(PaymentID);
			bool result;
			if (singlePayInfoByID.Rows.Count == 0)
			{
				result = false;
			}
			else
			{
				S_PayInfo.HLShop_PayInfoRow hLShop_PayInfoRow = singlePayInfoByID[0];
				if (hLShop_PayInfoRow.Status != status)
				{
					hLShop_PayInfoRow.Status = status;
					hLShop_PayInfoRow.eBankInfo = eBankInfo;
					if (status == "Pay")
					{
						Shop_Order shop_Order = new Shop_Order(this.conn);
						shop_Order.updateStatus(hLShop_PayInfoRow.OrderFormNum, "1", "", "");
					}
					result = (Shop_PayInfo.Adapter.Update(hLShop_PayInfoRow) == 1);
				}
				else
				{
					result = false;
				}
			}
			return result;
		}
		public DataTable GetSinglePayInfoByID(int PaymentID)
		{
			return Shop_PayInfo.Adapter.GetSinglePayInfoByID(PaymentID);
		}
		public DataTable GetPayInfoByUserName(string UserName)
		{
			return Shop_PayInfo.Adapter.GetPayInfoByUserName(UserName);
		}
		public DataTable GetPayInfoByUserID(int UserID)
		{
			DataTable result;
			if (UserID > 0)
			{
				result = this.conn.GetDataTable("Select * From [HLShop_PayInfo] Where UserID=" + UserID);
			}
			else
			{
				result = null;
			}
			return result;
		}
		public DataTable GetPayInfoByUserID(string wherestr, int UserID, params IDbDataParameter[] param)
		{
			DataTable result;
			if (UserID > 0)
			{
				if (!string.IsNullOrEmpty(wherestr))
				{
					wherestr += " and ";
				}
				result = this.conn.GetDataTable(string.Concat(new object[]
				{
					"Select * From [HLShop_PayInfo] Where ",
					wherestr,
					" UserID=",
					UserID,
					" ORDER BY PayTime DESC"
				}), param);
			}
			else
			{
				result = null;
			}
			return result;
		}
		public DataTable GetPayInfobyOrderFormNum(string OrderFormNum)
		{
			return Shop_PayInfo.Adapter.GetPayInfobyOrderFormNum(OrderFormNum);
		}
		public DataTable GetPayInfoList(string eBankID, string UserName, int SalerID, string BeginTime, string EndTime, string Status, string eBankInfo)
		{
			return Shop_PayInfo.Adapter.GetPayInfoList(eBankID, UserName, new int?(SalerID), BeginTime, EndTime, Status, eBankInfo);
		}
	}
}
